package com.lhg.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;

public class client {
    public static void main(String[] args) throws IOException {
        ThreadGroup threadGroup = new Thread().getThreadGroup();
        // 创建Socket
        Socket socket = new Socket();
        // 使用这个socket进行连接
        socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(),8080));
        //socket.connect(new InetSocketAddress("192.168.1.123",9000));

        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("{\"password\":\"123456\"}".getBytes());
        outputStream.flush();
        byte[] buffer = new byte[1024 * 1024];
        int len;
        while ((len = inputStream.read(buffer)) != -1){
            System.out.println(new String(buffer,0,len));
        }
        outputStream.close();
        inputStream.close();
        socket.close();
    }

}
